﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>产品列表</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="/style/admin/style/adminStyle.css" rel="stylesheet" type="text/css" />
        <script src="/style/admin/js/jquery.js"></script>
        <script src="/style/admin/js/public.js"></script>
    </head>
    <body>
        <div class="wrap">
            <div class="page-title">
                <span class="modular fl"><i></i><em>产品列表</em></span>
                <span class="modular fr"><a href="/admin/types/create" class="pt-link-btn">+添加商品</a></span>
            </div>
            <div class="operate">
                <form action="/admin/types/res" method="post"> 
                    {{ csrf_field() }}
                    <input type="text" name="name" class="textBox length-long" placeholder="输入产品名称..."/>
                    <input type="submit" value="查询" class="tdBtn"/>
                </form>
            </div>
            <table class="list-style Interlaced">
                <tr>
                    <th>ID编号</th>
                    <th>产品</th>
                    <th>名称</th>
                    <th>市场价</th>
                    <th>会员价</th>
                    <th>库存</th>
                    <th>精品</th>
                    <th>新品</th>
                    <th>热销</th>
                    <th>操作</th>
                </tr>
                @foreach($data as $value)
                <tr>
                    <td>
                        <span>
                            <input type="checkbox" value="{{$value->id}}" class="middle children-checkbox ckb"/>
                            <i>{{$value->id}}</i>
                        </span>
                    </td>
                    <td class="center pic-area"><img src="{{$value->img}}" class="thumbnail"/></td>
                    <td class="td-name">
                        <span class="ellipsis td-name block" style="text-align: center;">{{$value->title}}</span>
                    </td>
                    <td class="center">
                        <span>
                            <i>￥</i>
                            <em>{{$value->m_price}}</em>
                        </span>
                    </td>
                    <td class="center">
                        <span>
                            <i>￥</i>
                            <em>{{$value->price}}</em>
                        </span>
                    </td>
                    <td class="center">
                        <span>
                            <em>{{$value->num}}</em>
                            <i>件</i>
                        </span>
                    </td>
                    @if($value->is_best==1)
                    <td class="center"><img src="/style/admin/images/yes.gif"/></td>
                    @else
                    <td class="center"><img src="/style/admin/images/no.gif"/></td>
                    @endif

                    @if($value->is_news==1)
                    <td class="center"><img src="/style/admin/images/yes.gif"/></td>
                    @else
                    <td class="center"><img src="/style/admin/images/no.gif"/></td>
                    @endif

                    @if($value->is_host==1)
                    <td class="center"><img src="/style/admin/images/yes.gif"/></td>
                    @else
                    <td class="center"><img src="/style/admin/images/no.gif"/></td>
                    @endif
                    <td class="center">
                        <a href="javascript::;" title="查看" target="_blank"><img src="/style/admin/images/icon_view.gif"/></a>
                        <a href="/admin/types/{{$value->id}}/edit" title="编辑"><img src="/style/admin/images/icon_edit.gif"/></a>
                        <a title="删除" href="javascript::;" onclick="del({{$value->id}});"><img src="/style/admin/images/icon_drop.gif"/></a>
                    </td>
                </tr> 
                @endforeach
            </table>
            <!-- BatchOperation -->
            <div style="overflow:hidden;">
                <!-- Operation -->
                <div class="BatchOperation fl">
                    <input type="checkbox" id="del" onclick="SelectAll()"/>
                    <label for="del" class="btnStyle middle">全选</label>
                    <input type="button" value="批量删除" onclick="all_Del()" class="btnStyle"/>
                </div>
                <!-- turn page -->
                <div class="turnPage center fr">
                    <a>第一页</a>
                    <a>1</a>
                    <a>最后一页</a>
                </div>
            </div>
        </div>
        <script>
            //ajax批量删除
        function all_Del(){
            var ids=""
            $(".ckb").each(function(){
                if($(this).is(':checked')){
                     ids+=","+$(this).val();//把要删除的id拼接成字符串
                } 
            }) 
            ids = ids.substring(1); // 对id进行处理，去除第一个逗号 
            if(ids.length==0){
                alert("请选择要删除的分类");
            }else{
                if(confirm("确定删除？删除后将无法恢复。")){
                    $.post("/admin/types/all_del",{"ids":ids,"_token":"{{csrf_token()}}","_method":"post"},function(data){
                        if(data==1){
                            window.location.reload();
                        }else{
                            alert(data);
                        }
                    })
                }
            } 
        }
        //全选或者全取消 
        function SelectAll(){ 
          $("#del").is(':checked')?$(".ckb").prop("checked",true):$(".ckb").prop("checked",false);  
        }
         function del(id){
              $.post("/admin/types/"+id,{"_token":"{{csrf_token()}}","_method":"delete"},function(data){
                  if(data==1){
                      window.location.reload();
                  }else{
                      alert(data);
                  } 
              })
         }
        </script>
    </body>
</html>